package com.night.sqlserver.controller;

import com.night.sqlserver.entity.source.Person;
import com.night.sqlserver.service.DataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/data")
public class DataController {

    @Autowired
    private DataService dataService;

    @RequestMapping(value = "table", method = RequestMethod.GET)
    public List<HashMap> findTable() {
        return dataService.findAllSourceTables();
    }

    @RequestMapping(value = "column", method = RequestMethod.GET)
    public List<HashMap> findColumn() {
        return dataService.findColumnByTable("cdsgus");
    }

    @RequestMapping(value = "transferTable", method = RequestMethod.GET)
    public void transferTable() {
        dataService.transferTable();
    }

    @RequestMapping(value = "transferData", method = RequestMethod.GET)
    public Map transferData() {
        return dataService.transferData();
    }

    @RequestMapping(value = "id", method = RequestMethod.GET)
    public Person selectById(@RequestParam String id) {
        return dataService.selectById(id);
    }

    @RequestMapping(value = "id", method = RequestMethod.POST)
    public int transferById(@RequestParam String id) {
        return dataService.transferById(id);
    }

    /**
     * 批量转存数据
     *
     * @return
     */
    @RequestMapping(value = "batch", method = RequestMethod.POST)
    public Map batch() {
        return dataService.batch();
    }

    /**
     * 使用mybatis支持的批量插入
     *
     * @return
     */
    @RequestMapping(value = "listBatch", method = RequestMethod.POST)
    public Map batchByList() {
        return dataService.batchByList();
    }

}
